package com.link.serve.constants;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.EnumSet;


public enum BizId {
    LINK(1), // link服务
    IM(3); // im服务

    private final int id;

    BizId(int id) {
        this.id = id;
    }

    public int getId() {
        return id;
    }

    //遍历枚举类成员来查看消息体id是否存在于枚举类中
    public static boolean isValid(int id) {
        return EnumSet.allOf(BizId.class).stream().anyMatch(biz -> biz.getId() == id);
    }

    public static BizId fromId(int id) {
        return EnumSet.allOf(BizId.class).stream()
                .filter(biz -> biz.getId() == id)
                .findFirst()
                .orElse(null);
    }
}